package com.funtonow.jqdk.fkcs.ui;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.funtonow.jqdk.R;
import com.funtonow.jqdk.adapter.MyFragmentPagerAdapter;
import com.funtonow.jqdk.base.BaseActivity;
import com.funtonow.jqdk.fkcs.ui.fragment.HKRecordFragment;
import com.funtonow.jqdk.fkcs.ui.fragment.JKRecordFragment;
import com.funtonow.jqdk.ui.fragment.ZXNoticeFragment;
import com.funtonow.jqdk.ui.fragment.ZXRecommendFragment;
import com.funtonow.jqdk.ui.fragment.ZXStrategyFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * @author Jiajien
 * @date 2019/8/22
 * 借还记录
 */
public class JhActivity extends BaseActivity {


    @BindView(R.id.my_tablayout)
    TabLayout tabLayout;
    @BindView(R.id.my_viewpager)
    ViewPager viewPager;

    private ArrayList<String> tab_title_list = new ArrayList<>();//存放标签页标题
    private ArrayList<Fragment> fragment_list = new ArrayList<>();//存放ViewPager下的Fragment
    private MyFragmentPagerAdapter adapter;//适配器

    @Override
    public int getLayoutRes() {
        return R.layout.activity_jh;
    }

    @Override
    public void onCreateActivity(@Nullable Bundle savedInstanceState) {
        initToolbar("借还记录");
        tab_title_list.add("借款记录");
        tab_title_list.add("还款记录");
        tabLayout.addTab(tabLayout.newTab().setText(tab_title_list.get(0)));
        tabLayout.addTab(tabLayout.newTab().setText(tab_title_list.get(1)));
        fragment_list.add(JKRecordFragment.newInstance());
        fragment_list.add(HKRecordFragment.newInstance());
        adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), tab_title_list, fragment_list);
        viewPager.setAdapter(adapter);//给ViewPager设置适配器
        viewPager.setOffscreenPageLimit(fragment_list.size());
        tabLayout.setupWithViewPager(viewPager);//将TabLayout与Viewpager联动起来
        tabLayout.setTabsFromPagerAdapter(adapter);//给TabLayout设置适配器

    }
}
